<div class="posts" id="posts">
<?php 
	$siteid = $site['id'];
	$postsqry = dbSelect('posts',array("site_id=$siteid","parent_id=0","type_id=1"),"ORDER BY publishdate DESC");

if(mysql_numrows($postsqry) > 0){ 
	while($posts = mysql_fetch_array($postsqry)){
		$userid = $posts['author_id'];
		$author = mysql_fetch_array(dbSelect('users',array("id=$userid")));
		$authorname = $author['firstname'].' '.$author['lastname'];
		$nicetime = nicetime($posts['publishdate']);
?>
	<div class="post">
		<div class="post_title"><?php echo $posts['title']; ?></div>
		<span class="post_author"><?php echo $authorname; ?></span>&nbsp;<span id="post_body"><?php echo urldecode($posts['post']); ?></span>
		<div class="post_datetime"><?php if($nicetime){echo $nicetime;} ?></div>
		<?php editDel($posts['id'],$posts['author_id'],'feed'); ?>
		<div class="comments">
		<h2><small>Comments</small><?php addCommentLink(); ?></h2>
			<?php 
			$commentsparentid = $posts['id'];
			$commentsqry = dbSelect('posts',array("site_id=$siteid","parent_id=$commentsparentid"));
			if(mysql_numrows($commentsqry) > 0){
				while($comments = mysql_fetch_array($commentsqry)){
					$userid = $comments['author_id'];
					$commentsauthor = mysql_fetch_array(dbSelect('users',array("id=$userid")));
					$commentsauthorname = $commentsauthor['firstname'].' '.$commentsauthor['lastname'];
					$commentsnicetime = nicetime($comments['publishdate']);
			?>
					<div class="comment">
						<span id="comment_author"><?php echo $commentsauthorname; ?></span>
						<span id="comment_body"><?php echo urldecode($comments['post']); ?></span>
						<div id="comment_datetime"><?php echo $commentsnicetime; ?></div>
						<?php editDel($comments['id'],$comments['author_id'],'comment'); ?>
					</div>
					
			<?php
				} /* /while comments */
				if($loggedin==1){
					echo '<div style="margin: 0px 0px 0px 10px;"><span class="fakelinkhighlight" onclick="$(\'#addcommentbox\').toggle();"><small>Leave a comment</small></span><span id="addcommentbox" style="display: none;"><br /><textarea id="addcomment" rows="3" name="addcomment" style="width: 600px;"></textarea><br /><input type="button" value="Save" /></div>';
				}
			}  /* /if comments */
			?>
			<div id="newcommentwrap">
				<form name="newcommentform" method="post">
					<table>
						<tr>
							<td>
								<!---<textarea id="newcomment" name="newcomment" rows="3" cols="50"></textarea>--->
							</td>
							<td>
								<!---<input type="submit" value="Save" />--->
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div><!--/comments-->
	</div><!--/post-->
<?php
	} /* /while posts */
}else{
	echo 'There are no posts yet.';
} /* /if posts */
?>
</div><!--/posts-->